<?php
/*
=====================================================
 Generic Toolbox - by Carl Wells
-----------------------------------------------------
-----------------------------------------------------
 Copyright (c) 2009 Carl Wells
=====================================================
 THIS IS COPYRIGHTED SOFTWARE
 PLEASE READ THE LICENSE AGREEMENT
=====================================================
 File: system/users/amenduser.php
-----------------------------------------------------
 Purpose: contains all functionality to amend a user in the database.
=====================================================
*/

// ----------------------------------------------
//  include CONFIG file
// ----------------------------------------------    
 	require_once 'config/config.php';
 
// ----------------------------------------------
//  include SESSION file
// ----------------------------------------------    
 	require_once 'core/sessions.class.php';
	
// ----------------------------------------------
//  Instantiate MAIN CORE class
// ----------------------------------------------    
 	require_once 'core/main.class.php';
 	$MAIN = new main();  
 	
 	$SESS= new Session(); 
 	
 	require_once 'users/userAccess.class.php';
 	$userAccess = new UserAccess();
 	
 //	$userAccess->isLoggedIn(10);
 	
 	require_once 'users/userController.class.php';
 	require_once 'users/user.class.php';
 	$userC = new UserController();
 	if ($_GET['id']){
 	$user = $userC->getUser($_GET['id']);
 	}else{
 	header("Location:users.php");
 	}
 	
 	
 	
 	
    
// ----------------------------------------------
//  Instantiate generic display class
// ----------------------------------------------    
 	require_once 'display/genericdisplay.class.php';
    $GENDISPLAY = new Genericdisplay();
    echo ($GENDISPLAY->html_header('admin_style.css'));
    
    // OPEN THE BODY FOR OUTPUT
	$GENDISPLAY->body_open();
	
// ----------------------------------------------
//  Instantiate admin display class
// ----------------------------------------------    
	require_once 'display/usersdisplay.class.php';
	$USERDISPLAY = new Usersdisplay();
	
	$db = new Connection();
	$sql = "SELECT * FROM `sectors`;";
	$result = $db->selectQuery($sql);
	
	$lobOptions = "";
	
	while ($options = mysql_fetch_array($result)){
		$lobOptions .= "<option";
		if ( $user->getLob() == $options['nameOfSector'] ) { $lobOptions .= " selected=\"selected\""; }
		$lobOptions .= " value=\"".$options['nameOfSector']."\">";
		$lobOptions .= $options['nameOfSector'];
		$lobOptions .= "</option>\n";
	}
    ?>
    
    <div id="maincontainer">

<?php echo ($USERDISPLAY->display_header()); ?>
<div id="contentwrapper">
<div id="contentcolumn">
<div class="innertube"><h3>Amend Users</h3>
<div id="wrapper">

	<div class="form-container">


	
	

	<form action="processadduser.php" method="post"  enctype="multipart/form-data" >
	<?php
	
	if ($_SESSION['submitted_form_fields']){
	$post = unserialize($_SESSION['submitted_form_fields']);
	echo ("<p class=\"error\">".$_SESSION['errMsg']."</p>");
	unset($_SESSION['submitted_form_fields']);
	}
	
	( $post['uname'] ) ? $username = $post['uname'] :	$username = "";
	( $post['pword'] ) ? $password = $post['pword'] :	$password = "";
	( $post['email'] ) ? $email = $post['email'] :	$email = "";
	( $post['fname'] ) ? $firstname = $post['fname'] :	$firstname = "";
	( $post['lname'] ) ? $lastname = $post['lname'] : $lastname = "";
	( $post['opsManager'] ) ? $opsManager = $post['opsManager'] :	$opsManager = "";
	( $post['opsemail'] ) ? $opsemail = $post['opsemail'] :	$opsemail = "";
	( $post['address1'] ) ? $address1 = $post['address1'] : $address1 = "";
	( $post['address2'] ) ? $address2 = $post['address2'] : $address2 = "";
	( $post['city'] ) ? $city = $post['city'] : $city = "";
	( $post['postcode'] ) ? $postcode = $post['postcode'] : $postcode = "";
	( $post['lob'] ) ? $lob = $post['lob'] : $lob = "";
	( $post['logo'] ) ? $logo = $post['logo'] :	$logo = "";
	( $post['desc'] ) ? $desc = $post['desc'] :	$desc = "";
	( $post['info'] ) ? $info = $post['info'] :	$info = "";
	
	
	?>
	
	
	
	
	<p class="legend"><strong>Note:</strong> Required fields are marked with an asterisk (<em>*</em>)</p>
	
	<fieldset>
		<legend>User Details</legend>
			<div><label for="uname">Username</label> <input id="uname" type="text" name="uname" value="<?php echo $user->getUsername(); ?>" <?php if ( $_SESSION['errCode'] == 1 ){ echo "class=\"error\""; } ?> /></div>
			<div><label for="logo">New Password?</label><input name="passwordToggle" id="passwordToggle" value="1" type="checkbox" onclick="javascript:toggleDisable(document.getElementById('pword'));"/> <br />
			<label for="pword">Password</label> <input id="pword" type="text" name="pword" value=""  disabled="disabled"/></div>
			<div><label for="email">Email Address </label> <input id="email" type="text" name="email" value="<?php echo $user->getEmail(); ?>" /></div>
	
			<div><label for="fname">First Name</label> <input id="fname" type="text" name="fname" value="<?php echo $user->getFirstname(); ?>" size="50" /></div>
			<div><label for="lname">Last Name</label> <input id="lname" type="text" name="lname" value="<?php echo $user->getLastname(); ?>" size="50" /></div>

	</fieldset>
    
    <fieldset>
		<legend>Manager Details</legend>
			<div><label for="opsManager">Operations Manager</label> <input id="opsManager" type="text" name="opsManager" value="<?php echo $user->getOpsManager(); ?>"/></div>
			<div><label for="opsemail">Email Address </label> <input id="opsemail" type="text" name="opsemail" value="<?php echo $user->getOpsemail(); ?>" />
			</div>

	</fieldset>
	
	<fieldset>
		<legend>Address Information</legend>
			<div><label for="address1">Address 1</label> <input id="address1" name="address1" type="text" size="50" value="<?php echo $user->getAddress1(); ?>"/></div>
			<div><label for="address2">Address 2</label> <input id="address2" name="address2" type="text" size="50" value="<?php echo $user->getaddress2(); ?>"/></div>
			<div><label for="city">Town/City</label> <input id="city" type="text" name="city" value="<?php echo $user->getCity(); ?>" size="12" />
            <div><label for="postcode">Postcode</label> <input id="postcode" type="text" name="postcode" value="<?php echo $user->getPostcode(); ?>"size="12" /></div>

			</div>
	</fieldset>
	
	
	
	<fieldset>
		<legend>Preferences</legend>
			<div>
				<label for="lob">Line Of Business</label>
				<select id="lob" name="lob">
					<optgroup label="Choose Line of business">
					<?php
					echo $lobOptions;
					?>
					</optgroup>
				</select>
			</div>
			
			<?php
				$al = $user->getaccessLevel();
			?>

			<div class="controlset">
				<span class="label">User Status</span>
				<input name="status" id="radio1" value="1" type="radio"  <?php if (isset( $al ) && $al == 1){ print "checked=\"checked\""; }?>/> <label for="radio1">User</label>
				<input name="status" id="radio2" value="9" type="radio" <?php if (isset( $al ) && $al == 9){ print "checked=\"checked\""; }?>/> <label for="radio2">Operations Manager</label>
				<input name="status" id="radio3" value="10" type="radio" <?php if (isset( $al ) && $al == 10){ print "checked=\"checked\""; }?>/> <label for="radio3">Admin</label>
			</div>		

			<div class="controlset">
				<span class="label">Extras</span>

				<div>
					<input name="logo" id="logo" value="1" type="checkbox" onclick="toggleDisable(document.getElementById('logoImage'));"/> <label for="logo">Logo</label> <br />
                    <input type=file name='logoImage' id="logoImage" class='bginput' disabled="disabled"><br />
				</div>
			</div>			
	</fieldset>
	
	
	
	<div class="buttonrow">
		<input type="submit" value="Save" class="button" />

		<input type="button" value="Discard" class="button" />
	</div>
	<input type="hidden" value="amenduser" name="amenduser"/>
	<input type="hidden" value="<?php echo $_GET['id']; ?>" name="userid"/>
	
	
	</form>
	
	</div><!-- /form-container -->
	
	
</div><!-- /wrapper -->

</div>
</div>
</div>

<div id="leftcolumn">
<div class="innertube">
<?php

 echo ($USERDISPLAY->display_main_admin_nav());
echo ($USERDISPLAY->display_main_user_nav());

?>
</div>
</div>

<div id="footer"><p>&copy; Aramark</div>

</div>

<?php

// writeTimes($title, $name, $startHour, $startMin, $endHour, $endMin, $interval)
/*require ("functions/extraFunctions.php");
$EXTRAFUNCTIONS  = new ExtraFunctions();
echo ( $EXTRAFUNCTIONS->discountTable("TEXT", "pdf"));*/

// ----------------------------------------------
//  Instantiate cp display class
// ----------------------------------------------    
        
   /* require 'db/dbconnect.class.php';
    $DB = new Connection();
    $DB->connectToServer();
    
    $sql = "SELECT * FROM extraFunctions WHERE `id` = 1";
    $result = $DB->selectQuery($sql);
	
	while($array = mysql_fetch_array($result)) {
	eval($array['code']);
	echo $html;
	}
*/
$GENDISPLAY->body_close();
$GENDISPLAY->html_close();
unset($_SESSION['submitted_form_fields']);
unset($_SESSION['errCode']);
?>

